package com.itheima;

import java.util.*;
import java.util.stream.Collectors;

public class topic128 {

    public static int topic128(int[] nums) {
        Map<Integer, Integer> map = new HashMap<Integer, Integer>();
        for (int i : nums) {
            if (map.containsKey(i)) {
                map.put(i, map.get(i) + 1);
            } else {
                map.put(i, 1);
            }
        }
        Set<Integer> set = map.keySet();
        List<Integer> list = set.stream().sorted().collect(Collectors.toList());
//        ArrayList<Integer> al = (ArrayList<Integer>)list;
//        System.out.println(list);
        int maxnum = 0;
        int num = 1;
        for (int i = 0; i < list.size(); ++i) {
            if (i + 1 < list.size() && list.get(i) + 1 == list.get(i + 1)) {
                num = num + 1;
            } else {
                if (maxnum < num) {
                    maxnum = num;
                }
                num = 1;
            }
        }

        return maxnum;
    }

    public static void main(String[] args) {
        int arr[] = {9,1,4,7,3,-1,0,5,8,-1,6};
        int res = topic128(arr);
        System.out.println(res);
    }
}
